﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gatheshop.Web.Plugin.Link.BLL;
using System.Web;
using System.Web.SessionState;
using Gatheshop.Common;

namespace Gatheshop.Web.Plugin.Link
{
    public class ajax : IHttpHandler, IRequiresSessionState
    {
        // Methods
        private void link_add(HttpContext context)
        {
            StringBuilder builder = new StringBuilder();
            LinkBLL link = new LinkBLL();
            Model.link model = new Model.link();
            string formString = GESRequest.GetFormString("txtCode");
            string str2 = GESRequest.GetFormString("txtTitle");
            string str3 = GESRequest.GetFormString("txtUserName");
            string str4 = GESRequest.GetFormString("txtUserTel");
            string str5 = GESRequest.GetFormString("txtEmail");
            string str6 = GESRequest.GetFormString("txtSiteUrl");
            string str7 = GESRequest.GetFormString("txtImgUrl");
            if (string.IsNullOrEmpty(formString))
            {
                context.Response.Write("{msg:0, msgbox:\"对不起，请输入验证码！\"}");
            }
            else if (context.Session["dt_session_code"] == null)
            {
                context.Response.Write("{msg:0, msgbox:\"对不起，系统找不到生成的验证码！\"}");
            }
            else if (formString.ToLower() != context.Session["dt_session_code"].ToString().ToLower())
            {
                context.Response.Write("{msg:0, msgbox:\"您输入的验证码与系统的不一致！\"}");
            }
            else if (string.IsNullOrEmpty(str2))
            {
                context.Response.Write("{msg: 0, msgbox: \"对不起，请输入网站标题！\"}");
            }
            else if (string.IsNullOrEmpty(str6))
            {
                context.Response.Write("{msg: 0, msgbox: \"对不起，请输入网站网址！\"}");
            }
            else
            {
                model.title = str2;
                model.is_lock = 1;
                model.is_red = 0;
                model.user_name = str3;
                model.user_tel = str4;
                model.email = str5;
                model.site_url = str6;
                model.img_url = str7;
                model.is_image = 1;
                if (string.IsNullOrEmpty(model.img_url))
                {
                    model.is_image = 0;
                }
                if (link.Add(model) > 0)
                {
                    context.Response.Write("{msg: 1, msgbox: \"恭喜您，提交成功啦！\"}");
                }
                else
                {
                    context.Response.Write("{msg: 0, msgbox: \"对不起，保存过程中发生错误！\"}");
                }
            }
        }

        public void ProcessRequest(HttpContext context)
        {
            string str = context.Request.Params["action"];
            string str2 = str;
            if ((str2 != null) && (str2 == "add"))
            {
                this.link_add(context);
            }
        }

        // Properties
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }


}
